<?php
	include "../../public/commom/config.php";
	include "../lock1.php";
	include "../../public/commom/commom.php";
	
	$name = "";
	$id = 0;
	if($_GET) {
		$id = $_GET["id"];
		
		$sql = "SELECT * FROM shop where id = $id";
		
		$result = mysqli_query($conn, $sql);
		
		while($row = mysqli_fetch_array($result)) {
			$name = $row["name"];
			$pice = $row["pice"];
			$inventory = $row["inventory"];
			$img = $row["img"];
			$bid = $row["brand_id"];
			$sheif = $row["sheif"];
		}
	}
?>

<!DOCTYPE html>
<html>
	
	<head>
		<meta charset="utf-8" />
		<title></title>
		<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" href="../public/css/index.css"/>
	</head>
	
	<body>
		<div class="container">
			<h1>修改商品</h1>
			<form action="xiugai1.php" method="post" enctype="multipart/form-data">
				<div class="form-group">
					<label>
						名称：<input type="text" class="form-control" name="name" value="<?php echo $name; ?>" autocomplete="off" />
					</label>
				</div>
				<div class="form-group">
					<label>
						价格：<input type="text" class="form-control" name="pice" value="<?php echo $pice; ?>" autocomplete="off" />
					</label>
				</div>
				<div class="form-group">
					<label>
						库存：<input type="text" class="form-control" name="inventory" value="<?php echo $inventory; ?>" autocomplete="off" />
					</label>
				</div>
				<div class="form-group">
					<label>
						商品品牌分类：
						<select name="brand_id">
							<?php
								include "../../public/commom/config.php";
								
								$csql = "SELECT * FROM class";
							
								$cresult = mysqli_query($conn, $csql);
								
								while($row = mysqli_fetch_array($cresult)) {
									echo "<option disabled>" . $row["name"] . "</option>";
									
									$bsql = "SELECT * FROM brand WHERE " . $row['id'] . " = class_id";
									
									$bresult = mysqli_query($conn, $bsql);
									
									while($row = mysqli_fetch_array($bresult)) {
										if($row["id"] == $bid) {
											echo "<option value=" . $row["id"] . " selected>" . $row["name"] . "</option>";
										}else {
											echo "<option value=" . $row["id"] . ">" . $row["name"] . "</option>";
										}
										
									}
									
								}
							?>
						</select>
					</label>
				</div>
					商品状态：
					<?php
						switch($sheif) {
							case 0:
								echo "<div class='radio'><label><input type='radio' name='sheif' value='0' checked>上架</label></div>
								<div class='radio'><label><input type='radio' name='sheif' value='1'>下架</label></div>";
							break;
							case 1:
								echo "<div class='radio'><label><input type='radio' name='sheif' value='0'>上架</label></div>
								<div class='radio'><label><input type='radio' name='sheif' value='1' checked>下架</label></div>";
							break;
						}	
							
						mysqli_close($conn);
					?>
					原图：
					<div class="form-group">
						<img src="<?php echo $imgPathThumb . $img; ?>"/>
					</div>
					<div class="form-group">
						<label>
							上传图片：
							<input type="file" name="img" accept="image/gif, image/jpeg, image/png, image/jpg, image/webp">
						</label>
					</div>
				<input type="hidden" name="id" value="<?php echo $id?>" />
				<input type="hidden" name="pimg" value="<?php echo $img?>" />
				<input type="submit" class="btn btn-primary" value="修改"/>
			</form>
		</div>
	</body>
	
</html>